package com.zz.controller;


import com.zz.Service.CommodityService;
import com.zz.entity.Commodity;

import com.zz.repository.CommodityRepository;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: java类作用描述
 * @Author: ll
 * @CreateDate: 2019/6/7$15:03$
 */
@RestController
public class CommodityController {
    @Resource
    CommodityService commodityService;
    @Resource
    CommodityRepository commodityRepository;


    @RequestMapping("/save")
    public String saveComm(Commodity commodity){

        commodity.setCommNumber("005");
        commodity.setCommName("桃子");
        commodity.setCommPrice("65");
        commodity.setCommType("水果");
        commodityService.saveCommodity(commodity);
        return "添加";
    }
    @RequestMapping("/delete")
    public String deleteComm( @RequestParam("id") Long id){
//        Commodity commodity=new Commodity();
        commodityRepository.deleteCommodityById(id);
        return "删除";

    }
@RequestMapping("/update")
public String updateComm(@RequestParam("id") Long id){
       Commodity  commodity=new Commodity();
       commodity.setCommNumber("777");
       commodity.setCommName("牛肉");
       commodity.setCommPrice("100");
       commodity.setCommType("肉类");
       commodity.setId(id);
       commodityRepository.save(commodity);
       return "修改";
}

@RequestMapping("/select")
    public  Commodity selectComm(@RequestParam("id") Long id){
        Commodity commodity=new Commodity();
        commodity=commodityRepository.findOne(id);
        return commodity;
}

}




